/*
 * CMediaFileReader.h
 *
 *  Created on: 2013-1-11
 *      Author: terry
 */

#ifndef CMEDIAFILEREADER_H_
#define CMEDIAFILEREADER_H_

#include "MediaFileFormat.h"
#include <stdio.h>
#include "MediaChunkIndex.h"

class CMediaFileReader
{
public:
    CMediaFileReader();
    virtual ~CMediaFileReader();


    int open(const char* filename);

    void close();

    bool isOpen();

    const MediaFileHeader& getFileHeader();

    int getDecoderTag();

    int read(unsigned char* buffer, int length, MediaChunkHeader& header);

    int64_t getFileSize();

    int64_t getDuration();

    double getPos();

    bool setPos(double pos);

    bool checkFileHeader(const MediaFileHeader& header);

    bool lookaside(MediaChunkHeader& header);

protected:
    void buildIndex();

private:
    HANDLE m_hFile;
    HANDLE m_hMap;
    BYTE*  m_pView;

    int64_t m_fileSize;
    MediaFileHeader m_mediaHeader;

    int64_t m_duration;

    int64_t m_curPos;
    
    MediaChunkIndexTable    m_indexTable;

};

#endif /* CMEDIAFILEREADER_H_ */
